﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PropertyManagement.yuanGong
{
    public partial class addYuanGong : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public void UpdateFile(string sPicName)
        {
            this.FileUpload1.PostedFile.SaveAs(sPicName);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string sfilename = "";

            if (FileUpload1.HasFile)
            {
                //判断图片文件扩展名是不是jpg/gif

                //
                string str = FileUpload1.PostedFile.FileName;
                int p1 = str.LastIndexOf("\\");
                int n1 = str.Length - p1 - 1;
                sfilename = str.Substring(p1 + 1, n1);

                string sPicName = Server.MapPath("~/picture/") + sfilename;
                this.Image1.ImageUrl = "~/picture/" + str;
                UpdateFile(sPicName);
                //this.Image1.ImageUrl = sPicName;
            }

            string sname, pwd, address, sex, birth, tel, zhiwu, photo;
            int n;

            sname = txtsname.Text;
            pwd = txtpwd.Text;
            address = txtAddress.Text;
            sex = RadioButtonList1.SelectedValue;
            birth = txtBirth.Text;
            tel = txtTel.Text;
            zhiwu = txtWork.Text;
            photo = sfilename;

            string strsql = "insert into syuangong(sname, pwd, address, sex, birth, tel, zhiwu, photo) values("
            + "'" + sname + "',"
            + "'" + pwd + "',"
            + "'" + address + "',"
            + "'" + sex + "',"
            + "'" + birth + "',"
            + "'" + tel + "',"
            + "'" + zhiwu + "',"
            + "'" + photo + "'"
            + ")";

            mydata myda = new mydata();
            n = myda.execSql(strsql);
            if (n > 0)
            {
                Response.Write("<script language=javascript> alert('添加数据成功') </script>");
            }
            else
            {
                Response.Write("<script language=javascript> alert('添加数据失败') </script>");
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("browerYuanGong.aspx");
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            Response.Redirect("selectYuanGong.aspx");
        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            Response.Redirect("browerPhoto.aspx");
        }
    }
}